package com.six.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.six.pojo.SalaryMain;
import com.six.pojo.vo.SalaryMainVo;
import com.six.result.Result;
import com.six.result.ResultUtils;
import com.six.service.SalaryMainService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/sam")
@Api(tags = "y工资月份信息")
@CrossOrigin
@ResponseBody
public class SalaryMainController {

    @Autowired
    private SalaryMainService salaryMainService;

    @PostMapping("/list")
    @ApiOperation(value = "查询所有的工资月份表")
    public Result list(@RequestBody SalaryMainVo salaryMainVo){
        Page<SalaryMain> page = new Page(salaryMainVo.getPage(),salaryMainVo.getLimit());
        LambdaQueryWrapper<SalaryMain> wrapper = new LambdaQueryWrapper();
        wrapper.eq(SalaryMain::getMonth,salaryMainVo.getMonth());
        Page<SalaryMain> salaryMains = salaryMainService.page(page, wrapper);
        return ResultUtils.buildSuccess(salaryMains.getTotal(),salaryMains.getRecords());
    }

    @PostMapping("/add")
    @ApiOperation(value = "增加工资月份信息")
    public Result add(@RequestBody SalaryMain salaryMain){
        salaryMain.setStatus("待审核");
        salaryMainService.save(salaryMain);
        return ResultUtils.buildSuccess();
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "根据id删除")
    public Result delete(@PathVariable("id") Long id){
        salaryMainService.removeById(id);
        return ResultUtils.buildSuccess();
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查找")
    public Result findOne(@PathVariable("id") Long id){
        SalaryMain salaryMain = salaryMainService.getById(id);
        return ResultUtils.buildSuccess(salaryMain);
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改状态信息")
    public Result update(@RequestBody SalaryMain salaryMain){
        salaryMainService.updateById(salaryMain);
        return ResultUtils.buildSuccess();
    }

}
